home *** CD-ROM | disk | FTP | other *** search
- // dvctrl.cpp : Implementation of the DVocx OLE control class.
-
- #include "stdafx.h"
- #include "dvocx.h"
-
- #include "std.h"
- #include "dvtools.h"
- #include "dvstd.h"
- #include "Tfundecl.h"
- #include "dvGR.h"
- #include "grfundecl.h"
- #include "vuerfundecl.h"
- #include "VOFUNDECL.H"
- #include "dvctrl.h"
-
- #include "DvocxPpg.h"
-
- #ifdef _DEBUG
- #define new DEBUG_NEW
- #undef THIS_FILE
- static char THIS_FILE[] = __FILE__;
- #endif
-
-
- IMPLEMENT_DYNCREATE(DVocx, COleControl)
-
-
- /////////////////////////////////////////////////////////////////////////////
- // Message map
-
- BEGIN_MESSAGE_MAP(DVocx, COleControl)
- //{{AFX_MSG_MAP(DVocx)
- ON_WM_TIMER()
- ON_WM_DESTROY()
- ON_WM_PAINT()
- //}}AFX_MSG_MAP
- ON_OLEVERB(AFX_IDS_VERB_PROPERTIES, OnProperties)
- ON_MESSAGE(VI_EXPOSE, OnExpose)
- ON_MESSAGE(VI_RESIZE, OnResize)
- END_MESSAGE_MAP()
-
-
- /////////////////////////////////////////////////////////////////////////////
- // Dispatch map
-
- BEGIN_DISPATCH_MAP(DVocx, COleControl)
- //{{AFX_DISPATCH_MAP(DVocx)
- DISP_PROPERTY_NOTIFY(DVocx, "UpdateRate", m_updateRate, OnUpdateRateChanged, VT_I4)
- DISP_PROPERTY_NOTIFY(DVocx, "UseDoubleBuffering", m_fUseDblBuf, OnUseDoubleBufferingChanged, VT_BOOL)
- DISP_PROPERTY_NOTIFY(DVocx, "ViewFile", m_viewFile, OnViewFileChanged, VT_BSTR)
- DISP_PROPERTY_NOTIFY(DVocx, "AutoUpdate", m_autoUpdate, OnAutoUpdateChanged, VT_BOOL)
- DISP_PROPERTY_NOTIFY(DVocx, "Scale", m_scale, OnScaleChanged, VT_R8)
- DISP_FUNCTION(DVocx, "StartUpdating", StartUpdating, VT_EMPTY, VTS_NONE)
- DISP_FUNCTION(DVocx, "StopUpdating", StopUpdating, VT_EMPTY, VTS_NONE)
- DISP_FUNCTION(DVocx, "SetView", SetView, VT_EMPTY, VTS_BSTR)
- DISP_FUNCTION(DVocx, "CloseView", CloseView, VT_EMPTY, VTS_NONE)
- DISP_FUNCTION(DVocx, "UpdateWindow", UpdateWindow, VT_EMPTY, VTS_NONE)
- DISP_FUNCTION(DVocx, "ZoomTo", ZoomTo, VT_EMPTY, VTS_R8)
- //}}AFX_DISPATCH_MAP
- DISP_FUNCTION_ID(DVocx, "AboutBox", DISPID_ABOUTBOX, AboutBox, VT_EMPTY, VTS_NONE)
- END_DISPATCH_MAP()
-
-
- /////////////////////////////////////////////////////////////////////////////
- // Event map
-
- BEGIN_EVENT_MAP(DVocx, COleControl)
- //{{AFX_EVENT_MAP(DVocx)
- // NOTE - ClassWizard will add and remove event map entries
- // DO NOT EDIT what you see in these blocks of generated code !
- //}}AFX_EVENT_MAP
- END_EVENT_MAP()
-
-
- /////////////////////////////////////////////////////////////////////////////
- // Property pages
-
- // TODO: Add more property pages as needed. Remember to increase the count!
- BEGIN_PROPPAGEIDS(DVocx, 1)
- PROPPAGEID(CDvocxPropPage::guid)
- END_PROPPAGEIDS(DVocx)
-
-
- /////////////////////////////////////////////////////////////////////////////
- // Initialize class factory and guid
-
- IMPLEMENT_OLECREATE_EX(DVocx, "DVOCX.DvocxCtrl.1",
- 0xf1e0ab13, 0xa1af, 0x11cf, 0xa7, 0x5e, 0x20, 0x4c, 0x4f, 0x4f, 0x50, 0x20)
-
-
- /////////////////////////////////////////////////////////////////////////////
- // Type library ID and version
-
- IMPLEMENT_OLETYPELIB(DVocx, _tlid, _wVerMajor, _wVerMinor)
-
-
- /////////////////////////////////////////////////////////////////////////////
- // Interface IDs
-
- const IID BASED_CODE IID_DDvocx =
- { 0xf1e0ab11, 0xa1af, 0x11cf, { 0xa7, 0x5e, 0x20, 0x4c, 0x4f, 0x4f, 0x50, 0x20 } };
- const IID BASED_CODE IID_DDvocxEvents =
- { 0xf1e0ab12, 0xa1af, 0x11cf, { 0xa7, 0x5e, 0x20, 0x4c, 0x4f, 0x4f, 0x50, 0x20 } };
-
-
- /////////////////////////////////////////////////////////////////////////////
- // Control type information
-
- static const DWORD BASED_CODE _dwDvocxOleMisc =
- OLEMISC_ACTIVATEWHENVISIBLE |
- OLEMISC_SETCLIENTSITEFIRST |
- OLEMISC_INSIDEOUT |
- OLEMISC_CANTLINKINSIDE |
- OLEMISC_RECOMPOSEONRESIZE;
-
- IMPLEMENT_OLECTLTYPE(DVocx, IDS_DVOCX, _dwDvocxOleMisc)
-
-
- /////////////////////////////////////////////////////////////////////////////
- // DVocx::DVocxFactory::UpdateRegistry -
- // Adds or removes system registry entries for DVocx
-
- BOOL DVocx::DVocxFactory::UpdateRegistry(BOOL bRegister)
- {
- if (bRegister)
- return AfxOleRegisterControlClass(
- AfxGetInstanceHandle(),
- m_clsid,
- m_lpszProgID,
- IDS_DVOCX,
- IDB_DVOCX,
- FALSE, // Not insertable
- _dwDvocxOleMisc,
- _tlid,
- _wVerMajor,
- _wVerMinor);
- else
- return AfxOleUnregisterClass(m_clsid, m_lpszProgID);
- }
-
-
- /////////////////////////////////////////////////////////////////////////////
- // DVocx::DVocx - Constructor
-
- DVocx::DVocx()
- : m_updateRate(250), m_screen(NULL), m_view(NULL),
- m_dp(NULL), ok_to_draw(FALSE)
- {
- InitializeIIDs(&IID_DDvocx, &IID_DDvocxEvents);
- dv_winproc = NULL;
- }
-
-
- /////////////////////////////////////////////////////////////////////////////
- // DVocx::~DVocx - Destructor
-
- DVocx::~DVocx()
- {
- // TODO: Cleanup your control's instance data here.
- }
-
-
- /////////////////////////////////////////////////////////////////////////////
- // DVocx::OnDraw - Drawing function
-
- void DVocx::OnDraw(
- CDC* pdc, const CRect& rcBounds, const CRect& rcInvalid)
- {
- // if m_screen is NULL the OCX window has not yet been created. The
- // class is recieving an OnDraw call from the system because the
- // container app. wants the OCX to draw itself on teh container app's
- // window. Unfortunately, DataViews can't do that because DVTOOLS
- // does not provide an interface to draw on a specifed HDC. Therefore,
- // we can not draw the view under this condition.
-
- if (m_screen == NULL)
- {
- pdc->TextOut(0,0,"DataViews OCX", 13);
- return;
- }
- }
-
-
- /////////////////////////////////////////////////////////////////////////////
- // DVocx::DoPropExchange - Persistence support
-
- void DVocx::DoPropExchange(CPropExchange* pPX)
- {
- ExchangeVersion(pPX, MAKELONG(_wVerMinor, _wVerMajor));
- COleControl::DoPropExchange(pPX);
- PX_Long(pPX, _T("UpdateRate"), m_updateRate, 250);
- PX_Bool(pPX, _T("UseDoubleBuffering"), m_fUseDblBuf, TRUE);
- PX_Bool(pPX, _T("AutoUpdate"), m_autoUpdate, FALSE);
- PX_String(pPX, _T("ViewFile"), m_viewFile, "logo.v");
-
- // TODO: Call PX_ functions for each persistent custom property.
-
- }
-
-
- /////////////////////////////////////////////////////////////////////////////
- // DVocx::OnResetState - Reset control to default state
-
- void DVocx::OnResetState()
- {
- COleControl::OnResetState(); // Resets defaults found in DoPropExchange
-
- // TODO: Reset any other control state here.
- }
-
-
- /////////////////////////////////////////////////////////////////////////////
- // DVocx::AboutBox - Display an "About" box to the user
-
- void DVocx::AboutBox()
- {
- CDialog dlgAbout(IDD_ABOUTBOX_DVOCX);
- dlgAbout.DoModal();
- }
-
-
- /////////////////////////////////////////////////////////////////////////////
- // DVocx message handlers
-
- void DVocx::StartUpdating()
- {
- // TODO: Add your dispatch handler code here
- if (m_autoUpdate)
- KillTimer((UINT)m_hWnd);
-
- SetTimer((UINT)m_hWnd, m_updateRate, NULL);
- m_autoUpdate = TRUE;
- }
-
- void DVocx::StopUpdating()
- {
- KillTimer((UINT)m_hWnd);
- m_autoUpdate = FALSE;
- }
-
- void DVocx::OnUpdateRateChanged()
- {
- if (m_view == NULL || m_screen == NULL)
- return;
-
- if (m_autoUpdate)
- {
- StartUpdating();
- }
-
- SetModifiedFlag();
- }
-
- void DVocx::OnTimer(UINT nIDEvent)
- {
- // TODO: Add your message handler code here and/or call default
-
- COleControl::OnTimer(nIDEvent);
- UpdateWindow();
- }
-
- LONG DVocx::OnExpose(UINT wParam, LONG lParam)
- {
- MSG a_msg; /* used to call GRwe_convert() */
- WINEVENT win_event; /* used to call GRwe_convert() */
-
- a_msg.hwnd = m_hWnd;
- a_msg.message = VI_EXPOSE;
- a_msg.wParam = wParam;
- a_msg.lParam = lParam;
- /* here, GRwe_convert() will fill in the region that */
- /* should be sent with TscRedraw */
- GRwe_convert((ADDRESS)&a_msg,&win_event);
- if ( ok_to_draw == TRUE )
- TscRedraw(m_screen,&(win_event.region));
-
- return 0;
- }
-
- LONG DVocx::OnResize(UINT wParam, LONG lParam)
- {
- TscReset(m_screen);
- return 0;
- }
-
- LRESULT DVocx::WindowProc( UINT msg, WPARAM wParam, LPARAM lParam )
- {
- LRESULT r = COleControl::WindowProc(msg, wParam, lParam);
-
- if ( dv_winproc != NULL )
- return( CallWindowProc(dv_winproc,m_hWnd, msg, wParam, lParam ));
- return r;
- }
-
-
- void DVocx::OnDestroy()
- {
- CloseView();
- TscCloseCurrentScreen();
- KillTimer((UINT)m_hWnd);
- COleControl::OnDestroy();
- }
-
- void DVocx::Init()
- {
- /* Initialize DataViews */
- /* Pass the window onto DataViews */
- m_screen = TscOpenSet( "W", NULL,
- V_WIN32_WINDOW_HANDLE, m_hWnd,
- V_ACTIVE_CURSOR,
- V_END_OF_LIST );
- if(!m_screen)
- {
- char buf[50];
- int error_code=TscOpenError();
- sprintf(buf,"Product is not validated. Error code %d.",error_code);
- MessageBox(buf,"Validation Error",MB_OK);
- exit(error_code);
- }
-
-
- /* get a pointer to the function that would */
- /* be the window proc for a window created */
- /* with TscOpenSet */
- if (dv_winproc == NULL)
- GRget(V_WIN32_WINDOWPROC,&dv_winproc,V_END_OF_LIST);
-
- GRset(V_WIN32_DOUBLE_BUFFER, m_fUseDblBuf,V_END_OF_LIST);
- if (m_viewFile[0])
- {
- SetView(m_viewFile);
- m_scale = TdpGetScale(m_dp);
-
- if (m_autoUpdate)
- StartUpdating();
- }
- }
-
- void DVocx::Paint (WPARAM wParam, LPARAM lParam)
- {
- PAINTSTRUCT ps;
- MSG a_msg; /* used to call GRwe_convert() */
- WINEVENT win_event; /* used to call GRwe_convert() */
-
- if ( dv_winproc == NULL )
- {
- BeginPaint(&ps);
- EndPaint(&ps);
- return;
- }
-
- /* this is how you should handle a WM_PAINT message for */
- /* a DVtools window */
- a_msg.hwnd = m_hWnd;
- a_msg.message = WM_PAINT;
- a_msg.wParam = wParam;
- a_msg.lParam = lParam;
- /* GRwe_convert will call BeginPaint() and EndPaint() */
- /* and fill in the win_event structure with the rectangle */
- /* that needs to be redrawn */
- GRwe_convert((ADDRESS)&a_msg,&win_event);
- if ( win_event.type == V_EXPOSE )
- TscRedraw(m_screen,&(win_event.region));
- }
-
- void DVocx::OnPaint()
- {
- CPaintDC dc(this); // device context for painting
-
- if (m_screen == NULL)
- Init();
-
- Paint((WPARAM)dc.m_hDC,0);
- }
-
- void DVocx::SetView(LPCTSTR szViewFile)
- {
- if (szViewFile == NULL)
- return;
-
- if (szViewFile[0] == '\0')
- return;
-
- if (m_screen == NULL)
- return;
-
- if (m_view)
- CloseView();
-
- m_view = TviLoad( (LPSTR)szViewFile );
- TviOpenData( m_view );
-
- m_dp = TdpCreate( m_screen, m_view, (RECTANGLE*)NULL, (RECTANGLE*)NULL );
- ok_to_draw = TRUE;
-
- TviReadData( m_view );
- TdpDraw( m_dp );
- }
-
- void DVocx::CloseView()
- {
- TscSetCurrentScreen(m_screen);
- TdpDestroy(m_dp);
- TviDestroy(m_view);
- m_view = NULL;
- m_dp = NULL;
- ok_to_draw = FALSE;
- // TODO: Add your dispatch handler code here
-
- }
-
- void DVocx::UpdateWindow()
- {
- TscSetCurrentScreen(m_screen);
- TviReadData( m_view );
- TdpDrawNext( m_dp );
- }
-
- void DVocx::OnUseDoubleBufferingChanged()
- {
- if (m_screen)
- GRset(V_WIN32_DOUBLE_BUFFER, m_fUseDblBuf,V_END_OF_LIST);
- }
-
- void DVocx::OnViewFileChanged()
- {
- SetView(m_viewFile);
- }
-
- void DVocx::OnAutoUpdateChanged()
- {
- if (m_autoUpdate)
- StartUpdating();
- else
- StopUpdating();
- }
-
- void DVocx::OnScaleChanged()
- {
- if (m_dp)
- {
- double scale = TdpGetScale(m_dp);
-
- TdpZoom(m_dp, m_scale / scale);
- Invalidate();
- }
- }
-
- void DVocx::ZoomTo(double scale)
- {
- if (m_dp)
- {
- TdpZoom(m_dp, scale);
- Invalidate();
- }
- }
-